package com.team.arms.tijian.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.team.arms.common.Result;
import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.tijian.entity.vo.AllVO;
import com.team.arms.tijian.entity.vo.PersonReviewVo;
import com.team.arms.tijian.mapper.PersonReviewMapper;
import com.team.arms.tijian.mapper.SysHealthExaminationMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 个人复检申请记录表 前端控制器
 * </p>
 *
 * @author Huazige
 * @since 2022-06-02
 */
@RestController
@RequestMapping("/review")
@Api(tags="体检-个人反馈模块")
@CrossOrigin
public class PersonReviewController {
    @Autowired
    PersonReviewMapper personReviewMapper;
    @Autowired
    SysHealthExaminationMapper sysHealthExaminationMapper;


    @ApiOperation("获取个人反馈所有数据")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/get")
    public AjaxResult getrecommend() {

        List<PersonReviewVo> list = personReviewMapper.getReview();
//

        if (list != null) {
            return AjaxResult.success("查询成功", list);
        } else {
            return AjaxResult.error("查询失败");
        }
    }

    @ApiOperation("下拉框查找查找个人反馈信息")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/found")
    public AjaxResult getReviewbyname(@RequestParam(value = "查询的字段") String field , @RequestParam(value = "查询的内容")String content) {

        List<PersonReviewVo> list = personReviewMapper.getReviewbyname(field,content);
//

        if (list != null) {
            return AjaxResult.success("查询成功", list);
        } else {
            return AjaxResult.error("查询失败");
        }
    }
    @ApiOperation("获取某个人的详情内容")
    @GetMapping(value = "/getall/{examineId}}")
    public AjaxResult selectall(
            @PathVariable("examineId")String examineId
    ) {

        List<AllVO> list = sysHealthExaminationMapper.select(examineId);
        return AjaxResult.success("查询成功",list) ;

    }
    @ApiOperation("复检/单个+批量删除")
    @DeleteMapping("/examineId")
    public Result deleteInformation(
            @ApiParam("体检编号") @RequestParam("examineId")List<String> deletelist ) {
        int delete =0;

        for ( String id:deletelist
        ) {
            QueryWrapper<entity.SysHealthExamination> wrapper = new QueryWrapper();
            wrapper.eq("examine_id",id);

            delete = sysHealthExaminationMapper.delete(wrapper);


        }
        if (delete>0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }
}

